package models

import (
	"fmt"
)
type User struct {
	Uid           int
	Sex           int
	Email         string
	Password      string
	Salt          string
	Nickname      string
	PhoneArea     int
	PhoneNumber   string
	UserPic       string
	AdminGroupId  int
	UserLevel     int
	GroupExpire   string
	MemberExpire  string
	Point         int
	Status        int
	UpdateTime    string
}

func (User) TableName() string {
	return "user"
}

func GetUserInfoByUid(uid int) (user User) {
	db.Where(User{Uid:uid}).First(&user)
	return
}

func GetUsersByIdIn(uid []int64) []*User {
	var users []*User
	DB:= db
	DB.Table("user").Select("uid ,userpic,nickname").Where("uid in (?)",uid).Find(&users).Limit(15)
	return users
}

func GetUidByUserAndPwd(nickname,password string) int {
	var user User
	db.Where(User{Nickname:nickname,Password:password}).First(&user)
	return user.Uid
}


func AddUser(nickname,password string)  {
	user:=User{Nickname:nickname,Password:password}
	fmt.Println(db.Create(&user).Error)
}

func UpdatePassword(nickname string, password string) {
	var user User
	db.Where(User{Nickname:nickname}).First(&user)
	db.Model(&user).Updates(User{
		Password:password,
	})
}

